//
//  JWRegisteredViewController.m
//  见闻新闻
//
//  Created by YQZ on 16/3/7.
//  Copyright © 2016年 JoanBoat. All rights reserved.
//

#import "JWRegisteredViewController.h"
#import <AFNetworking.h>

@interface JWRegisteredViewController ()
@property (weak, nonatomic) IBOutlet UITextField *registerusernameText;
@property (weak, nonatomic) IBOutlet UITextField *registerPasswordText;
@property (weak, nonatomic) IBOutlet UITextField *registerUsernameEmail;

@property (weak, nonatomic) IBOutlet UITextField *registerUserTelText;

@property (weak, nonatomic) IBOutlet UITextField *registeruserSexText;
@property (weak, nonatomic) IBOutlet UITextField *nichengtext;

@end

@implementation JWRegisteredViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)regist {
    
    AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];

    
    NSDictionary *parameters = @{@"username" : self.registerusernameText.text,
                                 @"password" : self.registerPasswordText.text,
                                 @"useremail" :self.registerUsernameEmail.text,
                                 @"tel" :self.registerUserTelText.text,
                                 @"sex" : self.registeruserSexText.text,
                                 @"nickname":self.nichengtext.text};
    
    
    NSString *userRegistPath = @"http://1.zhixinnews.applinzi.com/Home/User/registered";

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    hud.labelText = @"正在修改";
    
    [manger POST:userRegistPath parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        if ([responseObject[@"code"]integerValue] == 1) {
            
             [[[UIAlertView alloc] initWithTitle:@"提示" message:@"注册成功" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil] show];
            hud.hidden = YES;
            
        }else{
            [[[UIAlertView alloc] initWithTitle:@"提示" message:responseObject[@"data"] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]show];
            hud.hidden = YES;
            
        }
        }failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            hud.hidden = YES;
        }];
}

- (IBAction)registerClick:(id)sender {
    
    if ([self.registerusernameText.text isEqualToString:@""]||[self.registerPasswordText.text isEqualToString:@""]||[self.registerUsernameEmail.text isEqualToString:@""]||[self.registeruserSexText.text isEqualToString:@""]||[self.registerUserTelText.text isEqualToString:@""]) {
        [[[UIAlertView alloc] initWithTitle:@"提示" message:@"注册信息不完整" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]show];
    }else{
        [self regist];
    }
}
- (IBAction)back:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
